package com.lilicould.dao;

import com.lilicould.entity.Apartment;
import com.lilicould.entity.Building;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

public interface HouseDao {

    @Select("SELECT * FROM apartment")
    ArrayList<Apartment> selectAllApartments(); //查找所有公寓

    @Select("SELECT * FROM building")
    ArrayList<Building> selectAllBuildings(); //查找所有公寓楼

    @Select("SELECT * FROM building WHERE building_id = #{buildingId}")
    Building selectBuildingByBuildingId(@Param("buildingId") String buildingId); //根据ID查询所属公寓楼信息

    // 插入楼栋信息
    @Insert("INSERT INTO building(building_id, address, manager_id) VALUES(#{buildingId}, #{address}, #{managerId})")
    int insertBuilding(@Param("buildingId") String buildingId, @Param("address") String address, @Param("managerId") String managerId);

    // 插入公寓信息
    @Insert("INSERT INTO apartment (building_id, apartment_no, bedroom_count, bathroom_count) VALUES (#{buildingId}, #{apartmentNo}, #{bedroomCount}, #{bathroomCount})")
    int insertApartment(@Param("buildingId") String buildingId, @Param("apartmentNo") String apartmentNo, @Param("bedroomCount") int bedroomCount, @Param("bathroomCount") int bathroomCount);

    // 通过楼栋编号和公寓编号获取公寓信息
    @Select("SELECT * FROM apartment WHERE building_id = #{buildingId} AND apartment_no = #{apartmentNo}")
    Apartment selectApartmentByBuildingIdAndApartmentNo(@Param("buildingId") String buildingId,@Param("apartmentNo") String apartmentNo);

}
